﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
using Geekees.Common.Controls;
using Geekees.Common.Utilities.Xml;
using EasyBuildingCMS.BLL.CoreEngine;
using EasyBuildingCMS.Base;

namespace EasyBuildingCMS.BuildingBlocks.Core
{
    public partial class DockPanel : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (((BasePage)this.Page).HasEditRight)
                this.PageModeToggleButton.Visible = true;
            else
                this.PageModeToggleButton.Visible = false;

            if (((EditablePage)this.Page).PageMode.Equals("View"))
            {
                this.PageModeToggleButton.Text = "Change to Edit Mode";
            }
            else
            {
                this.PageModeToggleButton.Text = "Change to View Mode";
            }

        }

        protected void PageModeToggleButton_Click(object sender, EventArgs e)
        {
            if (((EditablePage)this.Page).PageMode.Equals("View"))
            {
                ((EditablePage)this.Page).PageMode = "Design";
                this.PageModeToggleButton.Text = "Change to View Mode";
            }
            else
            {
                ((EditablePage)this.Page).PageMode = "View";
                this.PageModeToggleButton.Text = "Change to Edit Mode";
            
            }

            string currentPage = BLL.Globals.CurrentPage;
            int pageID = (int)(BLL.Helper.ToInt(currentPage));
            PageRepository pageRepository = new PageRepository();

            Response.Redirect("~/Default.aspx?virtualHandleName=" + pageRepository.GetPageByID(pageID).VirtualHandleName);
        }

    }
}